<?php
include_once ("slide.php");
include_once ("videoPlayer.php");

class uploadSlideManagement {
	public function displaySlidesScrollBar($pathSlides) {
		echo '<div id="slideDisplay">';
		echo '<div class="scrollbar">
				<div class="handle">
					<div class="mousearea">
					</div>
				</div>
			</div>';
		echo '<div id="scrollBarSlides" class="frame">
				<ul class="slidee">
					<li>Add new Slide</li>';
		$directory = new DirectoryIterator($pathSlides);
		$slides;
		$relativeFolder = str_replace($GLOBALS['baseDir'], '', $pathSlides);

		foreach ($directory as $fileinfo) {
			if ($fileinfo -> isFile()) {
				$slide = $fileinfo -> getFilename();
				if ($slide != "") {
					$pathSlide = $relativeFolder . $slide;
					echo '<li><img src="' . $pathSlide . '" id="' . $slide . '" height="100" width="100"></li>';
				}
			}
		}
		echo '</ul>
			  </div>';
		echo '</div>';
	}

	public function processConfigurationFile($pathToFile, $folderPath, $idVideo) {

		//open the configuration file
		$config = fopen($pathToFile, 'rb');
		//read all lines and process
		while (($line = fgets($config))) {
			$splitLine = preg_split('/ /', $line);
			$realPath = $folderPath . '-' . $splitLine[2] . '.jpg';

			//If the line is well formed
			if (count($splitLine) == 3 && is_numeric($splitLine[0]) && strlen($splitLine[1]) == 1 && realpath($realPath)) {
				//create and add the slide to the database
				$slide = new slide();
				$slide -> addSlide($idVideo, intval($splitLine[0]), $splitLine[1], $realPath);
			} else {
				//configuration file badly formed
				header("location:index.php?page=upload&errS=-3");
				exit ;
			}
		}

	}

	public function displayVideo($video) {
		echo '<div id="videoBlock">';
		$player = new videoPlayer($video);
		$player -> displayVideoSimple();
		echo '</div>';
	}

	public function displaySideListSlides($video, $path) {
		echo '<aside id="listSlidesAdded"> <table id="listAddedSlides"> <tr><th>Slides Added</th></tr></table>';
		$this -> displaySaveButton($video, $path);
		echo '</aside>';
	}

	public function displaySaveButton($video, $path) {
		echo '<form action="index.php?page=videoList" method="POST" onSubmit="return saveAllSelectedSlides(' . $video -> getIdVideo() . ',' . "'" . $path . "'" . ');">';
		echo '<input type="submit" id="saveAll" value="Save Slides"/>';
		echo '</form>';
	}

}
?>